﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace AsyncUnitTest
{
    public class MyTest8
    {
        public static void Go()
        {
            DemoAsync().Wait();
        }


        private static async Task DemoAsync()
        {
            var task1 = Task.Run(() => 
            {
                ThreadShow("task1");
                Thread.Sleep(300);
            });

            var task2 = new Task(() =>
            {
                ThreadShow("task2");
                Thread.Sleep(300);
            }, TaskCreationOptions.LongRunning);
            task2.Start();

            var task3 = Task.Factory.StartNew(() =>
            {
                ThreadShow("task3");
                Thread.Sleep(300);
            });

            await Task.WhenAll(task1, task2, task3);
        }

        private static void ThreadShow(string name)
        {
            Console.WriteLine($"{name} 线程id:{Thread.CurrentThread.ManagedThreadId}，" +
                $"是否是后台线程：{Thread.CurrentThread.IsBackground}，" +
                $"是否是线程池线程 {Thread.CurrentThread.IsThreadPoolThread} ");
        }

    }
}
